package com.bian.springboot04thymeleaf.controller;

import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author bianpengfei
 * @create 2019-01-30 15:22
 **/
@Controller
public class LoginController {

    @PostMapping(value = "/user/login")
    public String login(@RequestParam("username") String username,
                        @RequestParam("password") String password,
                        Map<String,Object> map,
                        HttpServletRequest request) {
        System.out.println(username);
        System.out.println(password);
        if (!StringUtils.isEmpty(username) && "456".equals(password)) {
            request.getSession().setAttribute("username", username);
            return "redirect:/main.html";
        }
        map.put("msg", "登录失败");
        return "login";

    }

}
